package com.hitqz.robot.biz.controller;

import com.hitqz.robot.api.business.model.param.tickets.AddOrUpDateTicketsFlowMathParams;
import com.hitqz.robot.api.business.model.vo.tickets.TicketsFlowMatchVo;
import com.hitqz.robot.api.common.entity.TicketsFlowMatch;
import com.hitqz.robot.biz.service.TicketsFlowMatchService;
import com.hitqz.robot.common.core.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author xupkun
 * @date 2024/12/26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/ticketsFlowMatch")
@Tag(name = "流程关键词匹配")
public class TicketsFlowMatchController {


    private final TicketsFlowMatchService ticketsFlowMatchService;

    @GetMapping
    @Operation(summary = "查询所有配置数据")
    public R<List<TicketsFlowMatchVo>> page() {
        return R.ok(ticketsFlowMatchService.list().stream().map(TicketsFlowMatchVo::new).toList());
    }
    @PostMapping
    @Operation(summary = "添加流程匹配")
    public R add(@RequestBody AddOrUpDateTicketsFlowMathParams addOrUpDateTicketsFlowMathParams) {
        TicketsFlowMatch ticketsFlowMatch = new TicketsFlowMatch();
        ticketsFlowMatch.setFlowName(addOrUpDateTicketsFlowMathParams.getFlowName());
        ticketsFlowMatch.setKeyWorld(addOrUpDateTicketsFlowMathParams.getKeyWorld());
        ticketsFlowMatchService.save(ticketsFlowMatch);
        return R.ok();
    }


    @PutMapping
    @Operation(summary = "查询所有配置数据")
    public R update(@RequestBody AddOrUpDateTicketsFlowMathParams addOrUpDateTicketsFlowMathParams) {
        TicketsFlowMatch ticketsFlowMatch = new TicketsFlowMatch();
        ticketsFlowMatch.setFlowName(addOrUpDateTicketsFlowMathParams.getFlowName());
        ticketsFlowMatch.setKeyWorld(addOrUpDateTicketsFlowMathParams.getKeyWorld());
        ticketsFlowMatchService.save(ticketsFlowMatch);
        return R.ok();
    }


    @DeleteMapping
    @Operation(summary = "删除")
    public R delete(@RequestBody Long[] ids) {
        ticketsFlowMatchService.removeBatchByIds(Arrays.asList(ids));
        return R.ok();
    }



}
